<%@page import="lbsproject.processaudit.model.CheckPoint"%>
<%@page import="lbsproject.processaudit.model.WorkRegion"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!-- Begin: WEB-INF/template/taskManage/addTask/checkPoint.jsp -->
<p class="form-item-title" align="center">
	<strong >新增任务执行地点</strong>
</p>
<form class = "form" action="AddCheckPoint" method="post">
<p  class="form-item">
	<label class="item-t" for="checkPointName">地点名称：</label class="item-t">
	<input size="13" type="text" name="checkPointName" value="" id="checkPointName" class="input"/>
</p>
<p  class="form-item">
	<label class="item-t" for="workRegionId">所属分区：</label class="item-t">
	<select id="workRegionId" name="workRegionId">
	<%
	@SuppressWarnings("unchecked")
	List<WorkRegion> allRegions = (List<WorkRegion>)request.getAttribute("workRegions");
	if (allRegions != null) {
		for (WorkRegion r: allRegions) {
	%>
		<option value="<%=r.getId()%>"><%=r.getName() %></option>
	<%
		}
	}
	%>
	</select>
	<a href="ShowWorkRegions" class = "text_add">创建新的<span>任务片区</span></a>
	</p>
	<p  class="form-item">

	<label class="item-t" for="jingdu">经度：</label class="item-t">
	<input size="10" type="text" name="jingdu" id="jingdu"></input>
	<label class="item-t" for="weidu">纬度：</label class="item-t">
	<input size="10" type="text" name="weidu" id="weidu"></input>
	</p>
	
	<p  class="form-item">
		<input class="btn search-btn" type="submit" value="  添加  " id = "search"/>
	</p>

	<div style="width:520px;height:340px;border:1px solid gray" id="baidumap"></div>
</form>
<ul class="tab-nav">
	<li class="current">&nbsp;已添加的巡检地点&nbsp; </li>
</ul>
<!-- show existed tasks -->
<div class="tab-content">
	<table class="table">
		<thead>
			<tr>
				<th width="20%">地点名称</th>
				<th width="20%">所属分区</th>
				<th width="20%">经度</th>
				<th width="20%">纬度</th>
				<th width="20%">操作</th>
			</tr>
		</thead>
		<tbody>
		<%
		@SuppressWarnings("unchecked")
		List<CheckPoint> checkPoints  = 
			(List<CheckPoint>)request.getAttribute("checkPoints");
		if (checkPoints  != null) {
			for (CheckPoint cp: checkPoints) {
		%>
			<tr>
				<td><%=cp.getName() %></td>
				<td><%=cp.getLocatedRegion().getName() %></td>
				<td><%=cp.getGpsJingdu() %></td>
				<td><%=cp.getGpsWeidu() %></td>
				<td><a href="ShowCheckTaskAssigns?location=<%=cp.getId()%>">指定任务执行人</a></td>
			</tr>
		<%
			}
		}
		%>
		</tbody>
	</table>
</div>
<script type="text/javascript">
var map = new BMap.Map("baidumap");                        // 创建Map实例
map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);     // 初始化地图,设置中心点坐标和地图级别
map.addControl(new BMap.NavigationControl());               // 添加平移缩放控件
map.addControl(new BMap.ScaleControl());                    // 添加比例尺控件
map.addControl(new BMap.OverviewMapControl());              //添加缩略地图控件

//以下部分展示已经存在的巡检地点。
var opts = new Array();
var infoWindow = new Array();
<% for (int i=0; i<checkPoints.size(); i++) { 
	  CheckPoint cp = checkPoints.get(i);
%>
var point = new BMap.Point(<%=cp.getGpsJingdu()%>, <%=cp.getGpsWeidu()%>);
var marker = new BMap.Marker(point);  // 创建标注
marker.setAnimation(BMAP_ANIMATION_BOUNCE);
//设置信息窗口
opts[<%=i%>] = {
		  width : 50,     // 信息窗口宽度
		  height: 20,     // 信息窗口高度
		  title : "<%='('+cp.getLocatedRegion().getName()+')'%>"  // 信息窗口标题
		};
infoWindow[<%=i%>] = new BMap.InfoWindow("<%=cp.getName() %>", opts[<%=i%>]);  // 创建信息窗口对象
marker.addEventListener("click", function(){          
	this.openInfoWindow(infoWindow[<%=i%>]);  
});
map.addOverlay(marker);              // 将标注添加到地图中
<% } %>

//以下部分增加地点点击事件，获取当前地点的坐标并填入输入框
var clickMarker;
map.addEventListener("click", function(e){
	map.removeOverlay(clickMarker);
	clickPoint = new BMap.Point(e.point.lng,e.point.lat);
	clickMarker = new BMap.Marker(clickPoint);
	
	map.addOverlay(clickMarker);  
	document.getElementById("jingdu").setAttribute("value", e.point.lng);
	document.getElementById("weidu").setAttribute("value", e.point.lat);
});
</script>
<!-- End -->